package com.wanghong.robot.im;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.HttpClient;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.httpclient.HttpClientUtil;
import com.httpclient.builder.HCB;
import com.httpclient.common.HttpConfig;
import com.wanghong.robot.dto.TuLingDTO;

@Component
public class TuLingRobot {
	private final static String APIKEY = "7f00a489f3019ad3a5b642c95b0cf733";
	private final static String TULING_URL = "http://www.tuling123.com/openapi/api";

	public static String sendMessage(String message) throws Exception {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("key", APIKEY);
		dataMap.put("info", message);
		HttpClient client = HCB.custom().build();
		HttpConfig config = HttpConfig.custom().url(TULING_URL).json(JSON.toJSONString(dataMap)).client(client);
		String response = HttpClientUtil.post(config);
		System.out.println("robot--->" + response);
		TuLingDTO tuLing = JSON.parseObject(response, TuLingDTO.class);
		return tuLing.getText();
	}

	public static void main(String[] args) throws Exception {
		TuLingRobot.sendMessage("今晚吃什么");
	}
}
